<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 哪个组件的template就用哪个组件的变量 -->
    <div id="app">
      <h2>组件传参-子传父-{{count}}</h2>
      <child @abc="fn"></child>
    </div>

    <script src="./lib/vue3.js"></script>
    <script>
      // 需要在子组件里面去触发父组件的事件
      //    1. 在父组件的子组件标签上面添加自定义事件
      //    2. 在子组件里面去通过this.$emit()来调用父组件的自定义事件
      // 可以在这个emit方法里面去传参

      const { createApp } = Vue;

      const Child = {
        data() {
          return {
            count: 10,
            name: "马口",
          };
        },
        template: `
          <div>child组件 - <button @click="handleClick">btn</button></div>
        `,
        methods: {
          handleClick() {
            // this.$emit("abc", this.count, this.name);
            this.$emit("abc", { count: this.count, name: this.name });
          },
        },
        // mounted() {
        //   this.$emit("abc");
        // },
      };

      createApp({
        data() {
          return {
            count: 0,
          };
        },
        methods: {
          // fn(count, name) {
          //   console.log("fn", count, name);
          //   this.count = count;
          // },
          fn({ name, count }) {
            console.log(count, name);
          },
        },
        components: {
          Child,
        },
      }).mount("#app");
    </script>
  </body>
</html>
